package com.lzy.canal.register.consumer;

import com.lzy.canal.component.filter.mysql.MySqlFilter;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 过程器
 *
 * @author lzy
 */
@Slf4j
public class MysqlFilterRegister {

    private final MySqlFilter mySqlFilter;

    private Map<String, MySqlFilter> filterConsumerMap = new ConcurrentHashMap<>();

    /**
     * 添加过滤器
     *
     * @param schemaName 库名名
     * @param filter     过滤器名称
     * @return
     */
    public MysqlFilterRegister add(String schemaName,  MySqlFilter filter) {
        filterConsumerMap.put(schemaName, filter);
        return this;
    }

    /**
     * 获取过滤器
     *
     * @param schemaName 数据库名称
     * @return
     */
    public MySqlFilter getFilter(String schemaName) {
        MySqlFilter filter = filterConsumerMap.get(schemaName);
        if (filter == null) {
            log.info("未找到过滤组件,使用默认过滤组件");
            return mySqlFilter;
        }
        return filter;
    }

    public MysqlFilterRegister(MySqlFilter mySqlFilter) {
        this.mySqlFilter = mySqlFilter;
    }

 }
